-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Ensure selfcheck file inherits directory permissions #13528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
1db6780
to
2e4aaa2
Compare
Hi @amol- thanks for your PR to pip. Please be aware it take the maintainers some time to review as we are all doing this on a volunteer basis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! This is on the right track. I have some small suggestions, but otherwise, this should be ready to merged very soon!
@@ -0,0 +1 @@ | |||
selfcheck file in cache directory has same permissions as the rest of the cache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selfcheck file in cache directory has same permissions as the rest of the cache. | |
Ensure the self-check files in the cache has same permissions as the rest of the cache. |
os.stat(directory).st_mode | ||
& 0o666 # select read/write permissions of cache directory | ||
| 0o600 # set owner read/write permissions | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.stat(directory).st_mode | |
& 0o666 # select read/write permissions of cache directory | |
| 0o600 # set owner read/write permissions | |
) | |
os.stat(directory).st_mode | |
& 0o666 # select read/write permissions of directory | |
| 0o600 # set owner read/write permissions | |
) |
|
||
statefile_permissions = os.stat(expected_path).st_mode & 0o666 | ||
selfcheckdir_permissions = os.stat(cache_dir / "selfcheck").st_mode & 0o666 | ||
assert statefile_permissions == selfcheckdir_permissions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
statefile_permissions = os.stat(expected_path).st_mode & 0o666 | |
selfcheckdir_permissions = os.stat(cache_dir / "selfcheck").st_mode & 0o666 | |
assert statefile_permissions == selfcheckdir_permissions | |
# Check that the self-check cache entries inherit the root cache permissions. | |
statefile_permissions = os.stat(expected_path).st_mode & 0o666 | |
selfcheckdir_permissions = os.stat(cache_dir / "selfcheck").st_mode & 0o666 | |
cache_permissions = os.stat(cache_dir).st_mode & 0o666 | |
assert statefile_permissions == selfcheckdir_permissions == cache_permissions |
Let's add a comment and also check against the root .cache
folder permissions as that's how the inheritance works with the network cache.
When writing files to cache pip does copy the permissions from the cache directory, this is an expected behaviour to ensure that any user that has access to the cache has also access to its content.
Copying the permissions explicitly is necessary due to the use of
adjacent_tmp_file
which by virtue oftempfile.mkstemp
(indirectly viaNamedTemporaryFile
) causes all files to be created with600
permissions.This is not happening for
selfcheck/XXXXX
by the way, which makes the selfcheck unaccessible by users different from the one that created the cache.This PullRequest creates an helper method
copy_directory_permissions
which allows both the cache and the selfcheck file to share the same logic in copying directory permissions and thus ensure consistency in cache files permissions.